<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>添加巡检信息</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <script type="text/javascript" src="../../js/jquery-2.0.3.min.js"></script>
  <link rel="stylesheet" href="../../layui/css/layui.css"  media="all">
</head>
<body>
    

         <!--表单-->
         <form id="myform" class="layui-form" method="" action="" style="margin-top: 30px;">

           <!--接收当前用户的账号-->
           <input type="hidden" name="lineman_account">

           <!--员工姓名-->
           <div class="layui-form-item">
             <label class="layui-form-label" style="width: 120px">任务编号：</label>
             <div class="layui-input-inline" style="width: 250px">
               <input type="text" name="task_id" lay-verify="required|task_id" autocomplete="off" class="layui-input">
             </div>
             <label class="layui-form-label" style="width: 120px">任务名称：</label>
             <div class="layui-input-inline" style="width: 250px">
               <input type="text" name="task_name" lay-verify="required|task_name" autocomplete="off" class="layui-input">
             </div>
           </div>



           <div class="layui-form-item">

             <label class="layui-form-label" style="width: 120px">巡检路线：</label>
             <div class="layui-input-inline" style="width: 250px">
               <select name="line_name" id="line_name" lay-verify="required" lay-filter="xmFilter">
                 <option value=""></option>
               </select>
             </div>

             <label class="layui-form-label" style="width: 120px">巡检员：</label>
             <div class="layui-input-inline" style="width: 250px">
               <select name="inspection_accont" id="dp" lay-verify="required" lay-filter="xmFilter">
                 <option value=""></option>
               </select>
             </div>


           </div>


           <div class="layui-form-item">
             <label class="layui-form-label" style="width: 120px">下发人：</label>

             <div class="layui-input-inline" style="width: 250px">
               <input type="text" name="admin" lay-verify="required|admin" disabled="disabled" autocomplete="off" class="layui-input">
             </div>

             <label class="layui-form-label" style="width: 120px">下发日期：</label>
             <div class="layui-input-inline" style="width: 250px">
               <input type="text" name="lssue_time" id="data" lay-verify="lssue_time"  disabled="disabled" autocomplete="off" class="layui-input">
             </div>
           </div>

           <!--备注-->
           <div class="layui-form-item layui-form-text" style="margin-left: 12px">
             <label class="layui-form-label">备注：</label>
             <div class="layui-input-block">
               <textarea  class="layui-textarea"  name="task_des" style="width: 270px"></textarea>
             </div>
           </div>

           <!--提交按钮-->
           <div class="layui-form-item" style="padding-left: 500px; margin-top:-200px;padding-top: -500px;">
             <div class="layui-input-block">
               <button type="button" class="layui-btn" lay-filter="add_inspetion" lay-submit="add_inspetion" style="margin-left: -60px;">添加</button>
               <button type="button" class="layui-btn layui-btn-normal" id="quit"style="margin-left: 60px">取消</button>
             </div>
           </div>

         </form>



<!--引入本地layui.js-->
<script src="../../layui/layui.js" charset="utf-8"></script>

   <script>
       layui.use(['form', 'layedit', 'laydate'], function(){
           var form = layui.form
               ,layer = layui.layer
               ,layedit = layui.layedit
               ,laydate = layui.laydate;

//            动态给巡检员框select中option添加巡检员内容
           $.ajax({
               url:"/testSelect.do",
               data:{},
               dataType:"json",
               type: 'post',
               success: function (data) {
                   console.log(data);//下面会提到这个data是什么值
                   //使用循环遍历，给下拉列表赋值
                   $.each(data.data, function (index, value) {
                       // console.log(value.department_id);
                       $('#dp').append(new Option("巡检员"+value.user_name,value.user_name));// 下拉菜单里添加元素
                   });
                   layui.form.render("select");//重新渲染 固定写法
               }
           });

//            动态给巡检线路框select中option添加线路内容
           $.ajax({
               url:"/showSelectLine.do",
               data:{},
               dataType:"json",
               type: 'post',
               success: function (data) {
//                   console.log(data);//下面会提到这个data是什么值
                   //使用循环遍历，给下拉列表赋值
                   $.each(data.data, function (index, value) {
                       // console.log(value.department_id);
                       $('#line_name').append(new Option(value.line_name,value.line_name));// 下拉菜单里添加元素
                   });
                   layui.form.render("select");//重新渲染 固定写法
               }
           });






           //日期
           laydate.render({

               elem: '#data',// input里时间的Id    .charAt(new Date().getDay()
               value:new Date(),
               done: function (value, date) {
               }
           });
           laydate.render({
               elem: '#date1'
           });

           //监听提交
           form.on('submit(add_inspetion)', function(data){
//               alert("提交按钮点击成功"+data.lineman_account)
               $.ajax({
                   url:"/addInspetion.do",
                   type:"post",
                   data:JSON.stringify(data.field),
                   dataType:"json",
                   success:function (result) {
                       if (result.code == 200){
                           layer.msg("添加成功,3秒后关闭当前以页...",{icon:1,time:3000,shade:0.4},function() {
                               parent.layer.close(parent.layer.index);
                           });

                       }else if (result.code == 500){
                           alert(result.message);
                       }else if (result.code == 405){
                           layer.msg(result.msg,{icon:5});
                       }
                   }
               });
               return false;
           });

       });
   </script>

   <script>
       //取消线路编辑
       $(document).on('click',"#quit",function () {
           parent.layer.close(parent.layer.index);
       });
   </script>



</body>
</html>